package com.nt.train.dao.impl;
import com.nt.train.dao.StudentDao;
import com.nt.train.entity.StudentPO;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
/**
 * @author hlf
 * @version 1.0
 * @date 2022/8/4 7:57
 */
@Repository
public class StudentDaoImpl implements StudentDao {


//    @Autowired
//    JdbcTemplate jdbcTemplate;

    @Override
    public StudentPO getByPrimaryKey(Integer id) {
        StudentPO student = new StudentPO();
        student.setId(33);
        student.setName("李春梅");
        student.setAge("28");
        return student;
    }

    /*
         * 增加Student
         * */
    @Override
    public void addStudent(StudentPO student) {
        //jdbcTemplate.update("insert into student (name,age) values (?,?)", student.getName(), student.getAge());
        System.out.println("增加Student成功");
    }

    /*
     * 删除Student
     * */
    @Override
    public void delStudentById(Long id) {
        //jdbcTemplate.update("delete from student where id=?", id);
        System.out.println("删除Student成功");
    }

    /*
     * 修改Student
     * */
    @Override
    public void updateStudent(StudentPO student) {
       // String sql = "UPDATE student SET name=?,age=? where id = ? ";
       // Object[] args = {student.getName(), student.getAge(), student.getId()};
       // jdbcTemplate.update(sql, args);
        System.out.println("修改Student成功");
    }

    /*
     * 查询
     * */
    @Override
    public List<StudentPO> selectStudent() {
        List<StudentPO>  pageList  = new ArrayList<StudentPO>();
        for(int i = 0; i < 2; i++){
            StudentPO student = new StudentPO();
            student.setId(i+1);
            student.setName("张三"+i);
            student.setAge((i+20)+"");
            pageList.add(student);
        }
        return pageList;
//        String sql = "select id,name,age from student";
//        return this.jdbcTemplate.query(sql, (rs, index) -> {
//            StudentPO student = new StudentPO();
//            student.setId(rs.getLong("id"));
//            student.setName(rs.getString("name"));
//            student.setAge(rs.getString("age"));
//            return student;
//        });
    }
}